define(['jquery', 'bootstrap', 'upload', 'validator'], function ($, undefined, Upload, Validator) {
    var Form = {
        config: {
            fieldlisttpl: '<dd class="form-inline"><input type="text" name="<%=name%>[<%=index%>][key]" class="form-control" value="<%=row.key%>" size="10" /> <input type="text" name="<%=name%>[<%=index%>][value]" class="form-control" value="<%=row.value%>" size="30" /> <span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span> <span class="btn btn-sm btn-primary btn-dragsort"><i class="fa fa-arrows"></i></span></dd>'
        },
        events: {
            validator: function (form, success, error, submit) {
                if (!form.is("form"))
                    return;
                //绑定表单事件
                form.validator($.extend({
                    validClass: 'has-success',
                    invalidClass: 'has-error',
                    bindClassTo: '.form-group',
                    formClass: 'n-default n-bootstrap',
                    msgClass: 'n-right',
                    stopOnError: true,
                    display: function (elem) {
                        return $(elem).closest('.form-group').find(".control-label").text().replace(/\:/, '');
                    },
                    dataFilter: function (data) {
                        if (data.code === 1) {
                            return "";
                        } else {
                            return data.msg;
                        }
                    },
                    target: function (input) {
                        var target = $(input).data("target");
                        if (target && $(target).size() > 0) {
                            return $(target);
                        }
                        var $formitem = $(input).closest('.form-group'),
                            $msgbox = $formitem.find('span.msg-box');
                        if (!$msgbox.length) {
                            return [];
                        }
                        return $msgbox;
                    },
                    valid: function (ret) {
                        var that = this, submitBtn = $(".layer-footer [type=submit]", form);
                        that.holdSubmit(true);
                        submitBtn.addClass("disabled");
                        //验证通过提交表单
                        var submitResult = Form.api.submit($(ret), function (data, ret) {
                            that.holdSubmit(false);
                            submitBtn.removeClass("disabled");
                            if (false === $(this).triggerHandler("success.form", [data, ret])) {
                                return false;
                            }
                            if (typeof success === 'function') {
                                if (false === success.call($(this), data, ret)) {
                                    return false;
                                }
                            }
                            //提示及关闭当前窗口
                            var msg = ret.hasOwnProperty("msg") && ret.msg !== "" ? ret.msg : __('Operation completed');
                            parent.Toastr.success(msg);
                            parent.$(".btn-refresh").trigger("click");
                            var index = parent.Layer.getFrameIndex(window.name);
                            parent.Layer.close(index);
                            return false;
                        }, function (data, ret) {
                            that.holdSubmit(false);
                            if (false === $(this).triggerHandler("error.form", [data, ret])) {
                                return false;
                            }
                            submitBtn.removeClass("disabled");
                            if (typeof error === 'function') {
                                if (false === error.call($(this), data, ret)) {
                                    return false;
                                }
                            }
                        }, submit);
                        //如果提交失败则释放锁定
                        if (!submitResult) {
                            that.holdSubmit(false);
                            submitBtn.removeClass("disabled");
                        }
                        return false;
                    }
                }, form.data("validator-options") || {}));

                //移除提交按钮的disabled类
                $(".layer-footer [type=submit],.fixed-footer [type=submit],.normal-footer [type=submit]", form).removeClass("disabled");
            },
            selectpicker: function (form) {
                //绑定select元素事件
                if ($(".selectpicker", form).size() > 0) {
                    require(['bootstrap-select', 'bootstrap-select-lang'], function () {
                        $('.selectpicker', form).selectpicker();
                    });
                }
            },
            selectpickernew: function (form) {
                //绑定select元素事件
                if ($(".selectpickernew", form).size() > 0) {
                    require(['bootstrap-select', 'bootstrap-select-lang'], function () {
                        $.each($('.selectpickernew', form),function(i){
                          var sobj = $(this);
                          var currentid = '';
                          if(typeof($(this).attr('dataurl'))!='undefined'){
                            var urlu = $(this).attr('dataurl')+'?1';
                            if(typeof($(this).attr('tree'))!='undefined'){
                                urlu = urlu + '&tree=1';
                            }
                            if(typeof($(this).attr('pid'))!='undefined'){
                                var pp = $(this).attr('pid');
                                urlu = urlu + '&pid=' + $("#"+pp).val();
                            }
                            if (typeof($(this).attr('datarelate'))!='undefined') {
                                urlu = urlu + '&' + $(this).attr('datarelate') + '=' + $("#" + $(this).attr('datarelate')).val();
                            }
                            if(typeof($(this).attr('currentid'))!='undefined'){
                                urlu = urlu + '&currentid=' + $(this).attr('currentid');
                            }

                            $.ajax({
                                type:'POST',
                                url:urlu,
                                dataType:'json',
                                async:false,
                                success:function(data){
                                    var str = '';
                                    str += '<option value="">请选择</option>';

                                    $.each(eval(data), function (k, v) {
                                        str += '<option value="' + v.itemid + '"';
                                        if(v.itemid==currentid||v.selected==1){
                                            str += ' selected="selected">';
                                        }else{
                                            str += '>';
                                        }
                                        str += v.name;
                                        str += '</option>';
                                    });
                                    /*
                                    $.each(eval(data), function (k1, v1) {});
                                    */
                                    sobj.html(str);
                                },
                                error: function () {
                                    alert('获取数据失败');
                                },
                                complete: function () {
                                }
                            });
                          }
                        });
                        $('.selectpickernew', form).selectpicker();
                    });
                }
            },
            selectpage: function (form) {
                //绑定selectpage元素事件
                if ($(".selectpage", form).size() > 0) {
                    require(['selectpage'], function () {
                        $('.selectpage', form).selectPage({
                            eAjaxSuccess: function (data) {
                                data.list = typeof data.rows !== 'undefined' ? data.rows : (typeof data.list !== 'undefined' ? data.list : []);
                                data.totalRow = typeof data.total !== 'undefined' ? data.total : (typeof data.totalRow !== 'undefined' ? data.totalRow : data.list.length);
                                return data;
                            }
                        });
                    });
                    //给隐藏的元素添加上validate验证触发事件
                    $(document).on("change", ".sp_hidden", function () {
                        $(this).trigger("validate");
                    });
                    $(document).on("change", ".sp_input", function () {
                        $(this).closest(".sp_container").find(".sp_hidden").trigger("change");
                    });
                    $(form).on("reset", function () {
                        setTimeout(function () {
                            $('.selectpage', form).selectPageClear();
                        }, 1);
                    });
                }
            },
            cxselect: function (form) {
                //绑定cxselect元素事件
                if ($("[data-toggle='cxselect']", form).size() > 0) {
                    require(['cxselect'], function () {
                        $.cxSelect.defaults.jsonName = 'name';
                        $.cxSelect.defaults.jsonValue = 'value';
                        $.cxSelect.defaults.jsonSpace = 'data';
                        $("[data-toggle='cxselect']", form).cxSelect();
                    });
                }
            },
            citypicker: function (form) {
                //绑定城市远程插件
                if ($("[data-toggle='city-picker']", form).size() > 0) {
                    require(['citypicker'], function () {
                    });
                }
            },
            datetimepicker: function (form) {
                //绑定日期时间元素事件
                if ($(".datetimepicker", form).size() > 0) {
                    require(['bootstrap-datetimepicker'], function () {
                        var options = {
                            format: 'YYYY-MM-DD',// HH:mm:ss
                            icons: {
                                time: 'fa fa-clock-o',
                                date: 'fa fa-calendar',
                                up: 'fa fa-chevron-up',
                                down: 'fa fa-chevron-down',
                                previous: 'fa fa-chevron-left',
                                next: 'fa fa-chevron-right',
                                today: 'fa fa-history',
                                clear: 'fa fa-trash',
                                close: 'fa fa-remove'
                            },
                            showTodayButton: true,
                            showClose: true
                        };
                        $('.datetimepicker', form).parent().css('position', 'relative');
                        $('.datetimepicker', form).datetimepicker(options);
                    });
                }
            },
            select2: function (form){
                if ($(".jscategoryselect2", form).size() > 0) {
                    $('.jscategoryselect2').select2({
                        width: '30%',
                        dropdownAutoWidth:true,
                        minimumResultsForSearch:0,
                        placeholder: {
                            id: '0', // the value of the option
                            text: '请选择类别'
                        },
                        allowClear: true,
                        ajax:{
                            type:'GET',
                            url: "/cms.php/ajax/category?pid=0",
                            dataType: 'json',
                            data: function (params) {
                                var query = { //请求的参数, 关键字和搜索条件之类的
                                  search: params.term //select搜索框里面的value
                                }
                                // Query paramters will be ?search=[term]&page=[page]
                                return query;
                            },
                            delay: 1500,
                            processResults: function (data, params) {
                                //返回的选项必须处理成以下格式
                                //var results =  [{ id: 0, text: 'enhancement' }, { id: 1, text: 'bug' }, { id: 2, text: 'duplicate' }, { id: 3, text: 'invalid' }, { id: 4, text: 'wontfix' }];
                                return {
                                  results: data  //必须赋值给results并且必须返回一个obj
                                };
                            },
                            cache: true
                        }
                    });
                    $('.jscategoryselect2').change(function(){
                        if($("#jscategoryselect2").children("p").length==0){
                            //var h = $("#jscategoryselect2").html();
                            $("#jscategoryselect2").append("");
                        }
                    });
                }
            },
            selectcategory: function(form){
                if ($(".selects3", form).size() > 0) {
                  $(".selects3").bind('click',function(){
                    var multiple = $(this).data('multiple');
                    var s1 = '';var p = '';
                    $.ajax({
                        url: '/cms.php/ajax/readcategory?catid='+$(this).attr("data-pid"),
                        type: 'post',
                        dataType: 'json',
                        async: false,
                        success: function (ret) {
                            $.each(ret.pss,function(k,v){

                            });
                            $.each(ret.ps,function(k,v){

                            });
                            $.each(ret.cs,function(k,v){
                                s1 = s1 + '<li><button class="btn btn-primary currents" id="'+v.id+'" type="button" data-multiple="'+multiple+'">'+v.name+'</button>';
                                if(v.child>0){
                                    s1 = s1 + '&nbsp;<button class="btn btn-primary childs" id="'+v.id+'" type="button" data-multiple="'+multiple+'">&gt;</button></li>';
                                }
                            });
                        }
                    });
                    //return s;
                    //var s1 = Layer.readcategory($(this).attr("data-pid"));
                    var s = '<div class="container">';
                    s = s + '<div class="row">';
                        s = s + '<div class="col-xs-12">';
                            s = s + '<ul id="breadcrumb" class="breadcrumb">';
                                s = s + '<li><a href="javascript:;" title="' + $(this).attr("data-pid") + '">回到顶级</a> <span class="divider">></span></li>';
                            s = s + '</ul>';
                        s = s + '</div>';
                    s = s + '</div>';
                    s = s + '<div class="row">';
                        s = s + '<ul id="dcategory" class="dcategory">';
                          s = s + s1;
                          s = s + '</ul>';
                      s = s + '</div>';
                      s = s + '</div>';
                      //Layer.fullscreen(s);
                      $(document).delegate(".breadcrumb a","click",function(){
                          var s = '';var p = '';
                          $.ajax({
                              url: '/cms.php/ajax/readcategory?catid='+$(this).prop("title"),
                              type: 'post',
                              dataType: 'json',
                              success: function (ret) {
                                  $.each(ret.pss,function(k,v){
                                      p = p + '<li><a href="javascript:;" title="' + v.id + '">';
                                      p = p + v.name + '</a>';
                                      p = p + '<span class="divider">></span></li>';
                                  });
                                  $.each(ret.ps,function(k,v){
                                      p = p + '<li><a href="javascript:;" title="' + v.id + '">';
                                      p = p + v.name + '</a>';
                                      p = p + '<span class="divider">></span></li>';
                                  });
                                  $.each(ret.cs,function(k,v){
                                      s = s + '<li><button class="btn btn-primary currents" id="'+v.id+'"	type="button">'+v.name+'</button>';
                                      if(v.child>0){
                                          s = s + '&nbsp;<button class="btn btn-primary childs" id="'+v.id+'" type="button">&gt;</button></li>';
                                      }
                                  });
                                  $("#breadcrumb").html('<li><a href="javascript:;" title="0">回到顶级</a> <span class="divider">></span></li>'+p);
                                  $("#dcategory").html(s);
                              }
                          });
                      });
                      $(document).delegate("button.childs","click",function(){
                            var s = '';var p = '';
                            var multiple = $(this).data('multiple');
                            //console.log($(this).data('multiple'));
                            $.ajax({
                                url: '/cms.php/ajax/readcategory?catid='+$(this).prop("id"),
                                type: 'post',
                                dataType: 'json',
                                success: function (ret) {
                                    $.each(ret.pss,function(k,v){
                                        p = p + '<li><a href="javascript:;" title="' + v.id + '">';
                                        p = p + v.name + '</a>';
                                        p = p + '<span class="divider">></span></li>';
                                    });
                                    $.each(ret.ps,function(k,v){
                                        p = p + '<li><a href="javascript:;" title="' + v.id + '">';
                                        p = p + v.name + '</a>';
                                        p = p + '<span class="divider">></span></li>';
                                    });
                                    $.each(ret.cs,function(k,v){
                                        s = s + '<li><button class="btn btn-primary currents" id="'+v.id+'"	type="button" data-multiple="'+multiple+'">'+v.name+'</button>';
                                        if(v.child>0){
                                          s = s + '&nbsp;<button class="btn btn-primary childs" id="'+v.id+'" type="button" data-multiple="'+multiple+'">&gt;</button></li>';
                                        }
                                    });
                                    $("#breadcrumb").html('<li><a href="javascript:;" title="0">回到顶级</a> <span class="divider">></span></li>'+p);
                                    $("#dcategory").html(s);
                                }
                            });
                        });
                      //选择当前类别
                      $(document).delegate("button.currents","click",function(){
                            var sbb = '<button class="btn btn-primary" id="'+$(this).prop("id")+'" type="button">'
                            sbb = sbb + $(this).html()+'&nbsp;&nbsp;<span class="fa fa-remove rmove"></span></button>'; 
                            //console.log($(this).data('multiple'));
                            if($(".selected3").html().indexOf(sbb)==-1){
                                if($(this).data('multiple')=='1'){
                                    //多选
                                    $(".selected3").html($(".selected3").html()+'&nbsp;'+sbb);
                                    if(sc!=''){
                                        $("#catid").val(sc+','+$(this).prop("id"));
                                    }else{
                                        $("#catid").val($(this).prop("id"));
                                    }
                                }else{
                                    //单选
                                    $(".selected3").html($(this).html());
                                    var sc = $("#catid").val();
                                    $("#catid").val($(this).prop("id"));
                                }                                
                            }
                            layer.closeAll();
                      });
                      $(document).delegate("span.rmove","click",function(){
                            $(this).parent().remove();
                            var bid = $(this).parent().attr("id");
                            var sary = $("#catid").val().split(',');
                            var sary2 = new Array();
                            for(var i=0; i<sary.length;i++){
                                if(sary[i]!=bid){
                                    sary2.push(sary[i]);
                                }
                            }
                            /*
                            console.log(sary2);
                            sary.each(function(){

                            });
                            */
                            $("#catid").val(sary2.join(','));
                            //sary.push(bid);console.log(sary);
                            layer.closeAll();
                      });
                      var ll = layer.open({
                        type: 1
                        ,title: '选择类别'
                        ,content: s
                        ,anim: 'down'
                        ,closeBtn: true
                        ,area:['90%','90%']
                        ,style: 'position:fixed; left:0; top:0; width:100%; height:100%; border: none; -webkit-animation-duration: .5s; animation-duration: .5s;'

                      });
                      //return ll;
                  });
                }
            },
            daterangepicker: function (form) {
                //绑定日期时间元素事件
                if ($(".datetimerange", form).size() > 0) {
                    require(['bootstrap-daterangepicker'], function () {
                        var ranges = {};
                        ranges[__('Today')] = [Moment().startOf('day'), Moment().endOf('day')];
                        ranges[__('Yesterday')] = [Moment().subtract(1, 'days').startOf('day'), Moment().subtract(1, 'days').endOf('day')];
                        ranges[__('Last 7 Days')] = [Moment().subtract(6, 'days').startOf('day'), Moment().endOf('day')];
                        ranges[__('Last 30 Days')] = [Moment().subtract(29, 'days').startOf('day'), Moment().endOf('day')];
                        ranges[__('This Month')] = [Moment().startOf('month'), Moment().endOf('month')];
                        ranges[__('Last Month')] = [Moment().subtract(1, 'month').startOf('month'), Moment().subtract(1, 'month').endOf('month')];
                        var options = {
                            timePicker: false,
                            autoUpdateInput: false,
                            timePickerSeconds: true,
                            timePicker24Hour: true,
                            autoApply: true,
                            locale: {
                                format: 'YYYY-MM-DD HH:mm:ss',
                                customRangeLabel: __("Custom Range"),
                                applyLabel: __("Apply"),
                                cancelLabel: __("Clear"),
                            },
                            ranges: ranges,
                        };
                        var origincallback = function (start, end) {
                            $(this.element).val(start.format(options.locale.format) + " - " + end.format(options.locale.format));
                            $(this.element).trigger('blur');
                        };
                        $(".datetimerange", form).each(function () {
                            var callback = typeof $(this).data('callback') == 'function' ? $(this).data('callback') : origincallback;
                            $(this).on('apply.daterangepicker', function (ev, picker) {
                                callback.call(picker, picker.startDate, picker.endDate);
                            });
                            $(this).on('cancel.daterangepicker', function (ev, picker) {
                                $(this).val('').trigger('blur');
                            });
                            $(this).daterangepicker($.extend({}, options, $(this).data()), callback);
                        });
                    });
                }
            },
            plupload: function (form) {
                //绑定plupload上传元素事件
                if ($(".plupload", form).size() > 0) {
                    Upload.api.plupload($(".plupload", form));
                }
            },
            faselect: function (form) {
                //绑定fachoose选择附件事件
                if ($(".fachoose", form).size() > 0) {
                    $(".fachoose", form).on('click', function () {
                        var that = this;
                        var multiple = $(this).data("multiple") ? $(this).data("multiple") : false;
                        var mimetype = $(this).data("mimetype") ? $(this).data("mimetype") : '';
                        parent.Fast.api.open("general/attachment.select?element_id=" + $(this).attr("id") + "&multiple=" + multiple + "&mimetype=" + mimetype, __('Choose'), {
                            callback: function (data) {
                                var button = $("#" + $(that).attr("id"));
                                var maxcount = $(button).data("maxcount");
                                var input_id = $(button).data("input-id") ? $(button).data("input-id") : "";
                                maxcount = typeof maxcount !== "undefined" ? maxcount : 0;
                                if (input_id && data.multiple) {
                                    var urlArr = [];
                                    var inputObj = $("#" + input_id);
                                    var value = $.trim(inputObj.val());
                                    if (value !== "") {
                                        urlArr.push(inputObj.val());
                                    }
                                    urlArr.push(data.url);
                                    var result = urlArr.join(",");
                                    if (maxcount > 0) {
                                        var nums = value === '' ? 0 : value.split(/\,/).length;
                                        var files = data.url !== "" ? data.url.split(/\,/) : [];
                                        var remains = maxcount - nums;
                                        if (files.length > remains) {
                                            Toastr.error(__('You can choose up to %d file%s', remains));
                                            return false;
                                        }
                                    }
                                    inputObj.val(result).trigger("change");
                                } else {
                                    $("#" + input_id).val(data.url).trigger("change");
                                }
                            }
                        });
                        return false;
                    });
                }
            },
            fieldlist: function (form) {
                //绑定fieldlist
                if ($(".fieldlist", form).size() > 0) {
                    var j=1;
                    $(".fieldlist", form).on("click", ".btn-append", function (e) {
                        var index = $(".btn-append").index($(this));

                        var rel = parseInt($(this).closest("dl").attr("rel"))+1;
                        var name = $(this).closest("dl").data("name");
                        $(this).closest("dl").attr("rel", rel);
                        var ss = '<dd class="form-inline">';
                        ss += '<input type="text" name="row[' + name + '][' + rel + '][key]" class="form-control" value="" />&nbsp;';
                        ss += '<input type="text" name="row[' + name + '][' + rel + '][value]" class="form-control" value="" />&nbsp;';
                        ss += '<span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span>&nbsp;';
                        ss += '<span class="btn btn-sm btn-primary btn-dragsort"><i class="fa fa-arrows"></i></span>';
                        ss += '</dd>';
                        $(ss).insertBefore($(this).parent());
                    });
                    $(".fieldlist", form).on("click", "dd .btn-remove", function () {
                        var rel = parseInt($(this).closest("dl").attr("rel"))-1;
                        $(this).closest("dl").attr("rel", rel);
                        $(this).parent().remove();
                    });
                    require(['dragsort', 'template'], function (undefined, Template) {
                        //刷新隐藏textarea的值
                        var refresh = function (name) {
                            var data = {};
                            var textarea = $("textarea[name='" + name + "']", form);
                            var container = textarea.closest("dl");
                            var template = container.data("template");
                            $.each($("input,select", container).serializeArray(), function (i, j) {
                                var reg = /\[(\w+)\]\[(\w+)\]$/g;
                                var match = reg.exec(j.name);
                                if (!match)
                                    return true;
                                match[1] = "x" + parseInt(match[1]);
                                if (typeof data[match[1]] == 'undefined') {
                                    data[match[1]] = {};
                                }
                                data[match[1]][match[2]] = j.value;
                            });
                            var result = template ? [] : {};
                            $.each(data, function (i, j) {
                                if (j) {
                                    if (!template) {
                                        if (j.key != '') {
                                            result[j.key] = j.value;
                                        }
                                    } else {
                                        result.push(j);
                                    }
                                }
                            });
                            textarea.val(JSON.stringify(result));
                        };
                        //监听文本框改变事件
                        $(document).on('change keyup', ".fieldlist input,.fieldlist textarea,.fieldlist select", function () {
                            refresh($(this).closest("dl").data("name"));
                        });

                        /*
                        //追加控制
                        $(".fieldlist", form).on("click", ".btn-append,.append", function (e, row) {
                            var container = $(this).closest("dl");
                            var index = container.data("index");
                            var name = container.data("name");
                            var template = container.data("template");
                            var data = container.data();
                            index = index ? parseInt(index) : 0;
                            container.data("index", index + 1);
                            var row = row ? row : {};
                            var vars = {index: index, name: name, data: data, row: row};
                            var html = template ? Template(template, vars) : Template.render(Form.config.fieldlisttpl, vars);
                            $(html).insertBefore($(this).closest("dd"));
                            $(this).trigger("fa.event.appendfieldlist", $(this).closest("dd").prev());
                        });



                        //渲染数据
                        $(".fieldlist", form).each(function () {
                            var container = this;
                            var textarea = $("textarea[name='" + $(this).data("name") + "']", form);
                            if (textarea.val() == '') {
                                return true;
                            }
                            var template = $(this).data("template");
                            var json = {};
                            try {
                                json = JSON.parse(textarea.val());
                            } catch (e) {
                            }
                            $.each(json, function (i, j) {
                                $(".btn-append,.append", container).trigger('click', template ? j : {
                                    key: i,
                                    value: j
                                });
                            });
                        });
                        */
                        //拖拽排序
                        $("dl.fieldlist", form).dragsort({
                            itemSelector: 'dd',
                            dragSelector: ".btn-dragsort",
                            dragEnd: function () {
                                refresh($(this).closest("dl").data("name"));
                            },
                            placeHolderTemplate: "<dd></dd>"
                        });
                    });
                }
            },
            bindevent: function (form) {

            }
        },
        api: {
            submit: function (form, success, error, submit) {
                if (form.size() === 0) {
                    Toastr.error("表单未初始化完成,无法提交");
                    return false;
                }
                if (typeof submit === 'function') {
                    if (false === submit.call(form, success, error)) {
                        return false;
                    }
                }
                var type = form.attr("method").toUpperCase();
                type = type && (type === 'GET' || type === 'POST') ? type : 'GET';
                url = form.attr("action");
                url = url ? url : location.href;
                //修复当存在多选项元素时提交的BUG
                var params = {};
                var multipleList = $("[name$='[]']", form);
                if (multipleList.size() > 0) {
                    var postFields = form.serializeArray().map(function (obj) {
                        return $(obj).prop("name");
                    });
                    $.each(multipleList, function (i, j) {
                        if (postFields.indexOf($(this).prop("name")) < 0) {
                            params[$(this).prop("name")] = '';
                        }
                    });
                }
                //调用Ajax请求方法
                Fast.api.ajax({
                    type: type,
                    url: url,
                    data: form.serialize() + (Object.keys(params).length > 0 ? '&' + $.param(params) : ''),
                    dataType: 'json',
                    complete: function (xhr) {
                        var token = xhr.getResponseHeader('__token__');
                        if (token) {
                            $("input[name='__token__']", form).val(token);
                        }
                    }
                }, function (data, ret) {
                    $('.form-group', form).removeClass('has-feedback has-success has-error');
                    if (data && typeof data === 'object') {
                        //刷新客户端token
                        if (typeof data.token !== 'undefined') {
                            $("input[name='__token__']", form).val(data.token);
                        }
                        //调用客户端事件
                        if (typeof data.callback !== 'undefined' && typeof data.callback === 'function') {
                            data.callback.call(form, data);
                        }
                    }
                    if (typeof success === 'function') {
                        if (false === success.call(form, data, ret)) {
                            return false;
                        }
                    }
                }, function (data, ret) {
                    if (data && typeof data === 'object' && typeof data.token !== 'undefined') {
                        $("input[name='__token__']", form).val(data.token);
                    }
                    if (typeof error === 'function') {
                        if (false === error.call(form, data, ret)) {
                            return false;
                        }
                    }
                });
                return true;
            },
            bindevent: function (form, success, error, submit) {
                form = typeof form === 'object' ? form : $(form);
                var events = Form.events;
                events.bindevent(form);
                events.validator(form, success, error, submit);
                events.selectpicker(form);
                events.daterangepicker(form);
                events.selectpage(form);
                events.cxselect(form);
                events.citypicker(form);
                events.datetimepicker(form);
                events.plupload(form);
                events.faselect(form);
                events.fieldlist(form);
                events.select2(form);
                events.selectpickernew(form);
                events.selectcategory(form);
            },
            custom: {}
        },
    };
    return Form;
});
